package com.lzx.java.smack.concurrent;

public class ReentrantLockTest1 {

	public static void main(String[] args) {
		Buffer buffer = new Buffer();
		Thread read = new Thread(new ReadThread(buffer));
		Thread write = new Thread(new WriteThread(buffer));
		read.start();
		write.start();
		
		write.interrupt();
		System.out.println("=============");
	}

	static class Buffer {

	}

	static class ReadThread implements Runnable {
		Buffer buffer;

		public ReadThread(Buffer buffer) {
			this.buffer = buffer;
		}

		@Override
		public void run() {
			synchronized (buffer) {
				System.out.println("read start ...");
				try {
					Thread.sleep(10000L);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println("read finished ...");
			}

		}

	}

	static class WriteThread implements Runnable {
		Buffer buffer;

		public WriteThread(Buffer buffer) {
			this.buffer = buffer;
		}

		@Override
		public void run() {
			synchronized (buffer) {
				System.out.println("write start ...");
				try {
					Thread.sleep(10000L);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println("write finished ...");
			}

		}

	}

}
